package sg.edu.nus.iss.cerberus.model;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * @author Lin Naing Oo(A0079983E)
 * */

public class CMemberMethod extends CMethod{
	
	private ArrayList<CMethodVariable> localFields;
	private String methodReturnType;
	
	//constructor with parameters and method variables 
	public CMemberMethod(String accessModi, String returnType, String name, ArrayList<String> params, ArrayList<CMethodVariable> fields){
		super(accessModi, name, params);
		this.methodReturnType = returnType;
		this.localFields = fields;
	}
	//constructor with parameters 
	public CMemberMethod(String accessModi, String returnType, String name, ArrayList<String> params){
		super(accessModi, name, params);
		this.methodReturnType = returnType;
	}
	
	//get and set for methodReturnType
	public void setMethodReturnType(String returnType){
		this.methodReturnType = returnType;
	}
	public String getMethodReturnType(){
		return this.methodReturnType;
	}
	
	//get and set for localFields
	public void setLocalFields(CMethodVariable field){
		this.localFields.add(field);
	}
	public CMethodVariable getLocalField(int index){
		return this.localFields.get(index);
	}
	public int getLocalFieldsCount(){
		return this.localFields.size();
	}
	
	//get signature of a method 
	//e.g. returnType ( parameterType, parameterType)
	public String getSignature(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(this.getMethodReturnType());
		if(this.getParametersCount() > 0){
			buffer.append(" (");
			for(int i = 0; i < this.getParametersCount(); i++){
				buffer.append(this.getParameterType(i));
				if(i < this.getParametersCount()-1)
					buffer.append(", ");
			}
			buffer.append(")");
			return buffer.toString();
		}else{
			buffer.append(" ()");
			return buffer.toString();
		}
	}
	
	
	public String getFullSignature(){
		StringBuffer buffer = new StringBuffer();
		buffer.append(this.getMethodReturnType());
		buffer.append(" "+getMethodName());
		if(this.getParametersCount() > 0){
			buffer.append(" (");
			for(int i = 0; i < this.getParametersCount(); i++){
				buffer.append(this.getParameterType(i));
				if(i < this.getParametersCount()-1)
					buffer.append(", ");
			}
			buffer.append(")");
			return buffer.toString();
		}else{
			buffer.append(" ()");
			return buffer.toString();
		}
	}
}
